package com.frostmourne.loreoriginex.objects.loreorigins;

import com.frostmourne.loreoriginex.objects.LoreOriginData;
import com.frostmourne.loreoriginex.objects.managers.PlayerDataManager;
import com.frostmourne.loreoriginex.utils.LangUtils;
import com.frostmourne.loreoriginex.utils.MathUtils;
import org.bukkit.entity.LivingEntity;

public class LoreOriginAttack {

    public final static String key = "Damage";

    public double getDamage(LivingEntity attacker,LivingEntity damaged){
        double damage = 1.00;
        System.out.println("attacker=" + attacker.getUniqueId());
        System.out.println(PlayerDataManager.getDataMap().keySet());
        if (PlayerDataManager.getDataMap().containsKey(attacker.getUniqueId())) {
            LoreOriginData data =
                    PlayerDataManager.getDataMap()
                            .get(attacker.getUniqueId()).getLoreOriginDataByKeyName(key);
            if (data == null){
                return damage;
            }
            if (data.getValues().size() == 1){
                damage = data.getValues().get(0);
            }else{
                damage = MathUtils.randomDouble(data.getValues().get(0),data.getValues().get(1));
            }
            damage = MathUtils.format(damage);
            String attackMess = LangUtils.getMess("Prefix") + LangUtils.getMess("Attacked")
                    .replace("<target>",damaged.getName())
                    .replace("<value>",String.valueOf(damage));
            String damageMess = LangUtils.getMess("Prefix") + LangUtils.getMess("Damaged")
                    .replace("<target>",damaged.getName())
                    .replace("<value>",String.valueOf(damage));

            attacker.sendMessage(attackMess);
            damaged.sendMessage(damageMess);
        }
        return damage;

    }

}
